package com.yunti.yntk.activity.zx;

import android.annotation.SuppressLint;
import android.content.Context;
import android.content.res.Resources;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.*;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.constraintlayout.widget.ConstraintLayout;
import com.qmuiteam.qmui.widget.dialog.QMUITipDialog;
import com.yunti.yntk.R;
import com.yunti.yntk.activity.BaseActivity;
import com.yunti.yntk.anotation.ViewInject;
import com.yunti.yntk.api.Result;
import com.yunti.yntk.api.req.ExamSpecialScoreReq;
import com.yunti.yntk.api.res.ExamSpecialArrange;
import com.yunti.yntk.api.res.ExamStuWithSpecialRes;
import com.yunti.yntk.api.res.GetSpecialGroupByXmdmReq;
import com.yunti.yntk.api.res.SpecialGroupRes;
import com.yunti.yntk.db.po.ExamItem;
import com.yunti.yntk.manager.ConfigManager;
import com.yunti.yntk.manager.NetWorkManager;
import com.yunti.yntk.util.BitmapUtils;
import com.yunti.yntk.util.CacheUtils;
import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;

import java.io.IOException;
import java.util.*;
import java.util.stream.Collectors;

public class ZxUpdateScoreActivity extends BaseActivity {
    @ViewInject(R.id.zxmcText)
    private TextView zxmcText;

    @ViewInject(R.id.zxxjText)
    private TextView zxxjText;

    @ViewInject(R.id.stuListView)
    private ListView stuListView;

    @ViewInject(R.id.name)
    private TextView nameText;

    @ViewInject(R.id.kh)
    private TextView kh;

    @ViewInject(R.id.zh)
    private TextView zh;

    @ViewInject(R.id.xh)
    private TextView xhText;

    @ViewInject(R.id.inputText)
    private TextView inputText;

    @ViewInject(R.id.cancelzb_button)
    private TextView cancelzb_button;

    @ViewInject(R.id.confirmzb_button)
    private TextView confirmzb_button;


    @ViewInject(R.id.groupListView)
    private ListView groupListView;


    @ViewInject(R.id.examItemListView)
    private ListView examItemListView;

    @ViewInject(R.id.selectZbButton)
    private LinearLayout selectZbButton;


    @ViewInject(R.id.keyBoardLayout)
    private ConstraintLayout keyBoardLayout;

    @ViewInject(R.id.groupLayout)
    private ConstraintLayout groupLayout;

    @ViewInject(R.id.selectZbText)
    private TextView selectZbText;

    @ViewInject(R.id.FanGuiButton)
    private TextView FanGuiButton;

    @ViewInject(R.id.QueKaoButton)
    private TextView QueKaoButton;

    @ViewInject(R.id.MianKaoButton)
    private TextView MianKaoButton;


    public String zxmc;

    public String zxdm;

    public Integer selectZb;

    public List<ExamItem> examItemList = new ArrayList<>();

    List<ExamStuWithSpecialRes> examStuWithSpecialResList = new ArrayList<>();

    List<ExamSpecialArrange> examSpecialArrangeList = new ArrayList<>();

    List<SpecialGroupRes> specialGroupResList = new ArrayList<>();

    private ZxStuAdapter zxStuAdapter;

    private ZxItemAdapter zxItemAdapter;

    private GroupItemAdapter groupItemAdapter;

    @Override
    public int initLayoutId() {
        return R.layout.activity_zxupdatescore;
    }

    @Override
    public void initView() {
        zxStuAdapter = new ZxStuAdapter(getBaseContext(), R.layout.item_zxstuscoreitemlist, examStuWithSpecialResList);
        stuListView.setAdapter(zxStuAdapter);

        zxItemAdapter = new ZxItemAdapter(getBaseContext(), R.layout.item_zxstuscoreitemlist, examSpecialArrangeList);
        examItemListView.setAdapter(zxItemAdapter);

        groupItemAdapter = new GroupItemAdapter(getBaseContext(), R.layout.item_zxstuscoreitemlist, specialGroupResList);
        groupListView.setAdapter(groupItemAdapter);
        groupLayout.setVisibility(View.GONE);

        this.findViewById(R.id.key1).setOnClickListener(this::onKey);
        this.findViewById(R.id.key2).setOnClickListener(this::onKey);
        this.findViewById(R.id.key3).setOnClickListener(this::onKey);
        this.findViewById(R.id.key4).setOnClickListener(this::onKey);
        this.findViewById(R.id.key5).setOnClickListener(this::onKey);
        this.findViewById(R.id.key6).setOnClickListener(this::onKey);
        this.findViewById(R.id.key7).setOnClickListener(this::onKey);
        this.findViewById(R.id.key8).setOnClickListener(this::onKey);
        this.findViewById(R.id.key9).setOnClickListener(this::onKey);
        this.findViewById(R.id.keysy).setOnClickListener(this::onKey);
        this.findViewById(R.id.keydy).setOnClickListener(this::onKey);
        this.findViewById(R.id.key0).setOnClickListener(this::onKey);

        this.findViewById(R.id.keydelete).setOnClickListener(this::delete);
        this.findViewById(R.id.keycancel).setOnClickListener(this::onKey);
        this.findViewById(R.id.keydiscount).setOnClickListener(this::onKey);
        this.findViewById(R.id.keyconfirm).setOnClickListener(this::onKey);

        this.findViewById(R.id.back).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                finish();
            }
        });

        selectZbButton.setOnClickListener(this::selectZb);
        cancelzb_button.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                selectZb = confirmSelectZb;
                groupItemAdapter.notifyDataSetChanged();
                groupLayout.setVisibility(View.GONE);
            }
        });
        confirmzb_button.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                confirmZb();
            }
        });
        FanGuiButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                inputStr.clear();
                inputStr.addAll(Arrays.asList('犯', '规'));
                inputText.setText("犯规");
            }
        });
        QueKaoButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                inputStr.clear();
                inputStr.addAll(Arrays.asList('缺', '考'));
                inputText.setText("缺考");
            }
        });
        MianKaoButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                inputStr.clear();
                inputStr.addAll(Arrays.asList('免', '考'));
                inputText.setText("免考");
            }
        });
    }

    private void confirmZb() {
        getStuList();
        selectZbText.setText("第" + selectZb + "组");
    }

    @Override
    public void initData() throws IOException {
        zxmc = CacheUtils.zxmc;
        zxdm = CacheUtils.zxdm;
        examItemList = CacheUtils.examItemList;
        zxmcText.setText(zxmc);
        StringBuilder text = new StringBuilder("");
        for (int i = 0; i < examItemList.size(); i++) {
            text.append(examItemList.get(i).getXmmc()).append("、");
        }
        zxxjText.setText(text);
        GetSpecialGroupByXmdmReq getSpecialGroupByXmdmReq = new GetSpecialGroupByXmdmReq();
        if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.N) {
            List<String> xbdmList = examItemList.stream().map(ExamItem::getXbdm).collect(Collectors.toList());
            getSpecialGroupByXmdmReq.setXbdmList(xbdmList);
        }

        if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.N) {
            List<String> xmdmList = examItemList.stream().map(ExamItem::getXmdm).collect(Collectors.toList());
            getSpecialGroupByXmdmReq.setXmdmList(xmdmList);
        }

        new Thread(() -> {
            Call<Result<List<SpecialGroupRes>>> call1 = NetWorkManager.getRequest().getSpecialGroupByXmdm(getSpecialGroupByXmdmReq);
            call1.enqueue(new Callback<Result<List<SpecialGroupRes>>>() {
                @Override
                public void onResponse(Call<Result<List<SpecialGroupRes>>> call, Response<Result<List<SpecialGroupRes>>> response) {
                    Result<List<SpecialGroupRes>> result = response.body();
                    if (result != null && result.getCode() == 200) {
                        List<SpecialGroupRes> specialGroupResList = result.getData();
                        ZxUpdateScoreActivity.this.specialGroupResList.clear();
                        ZxUpdateScoreActivity.this.specialGroupResList.addAll(specialGroupResList);
//                    examStuWithSpecialRes.clear();
//                    examStuWithSpecialRes.addAll(localExamItemList);
                        runOnUiThread(() -> {
                            if (specialGroupResList.size() > 0) {
                                selectZb = specialGroupResList.get(0).getGroupNum();
                                confirmZb();
                            }
                            groupItemAdapter.notifyDataSetChanged();
                        });
//                    Toast.makeText(getBaseContext(), "同步成功！", Toast.LENGTH_LONG).show();
                    }
                }

                @Override
                public void onFailure(Call<Result<List<SpecialGroupRes>>> call, Throwable t) {

                }
            });

        }).start();

    }

    Integer confirmSelectZb;

    public void getStuList() {
        new Thread(()->{
            GetSpecialGroupByXmdmReq getSpecialGroupByXmdmReq = new GetSpecialGroupByXmdmReq();
            getSpecialGroupByXmdmReq.setZxzb(selectZb + "");
            if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.N) {
                List<String> xbdmList = examItemList.stream().map(ExamItem::getXbdm).collect(Collectors.toList());
                getSpecialGroupByXmdmReq.setXbdmList(xbdmList);
            }

            confirmSelectZb = selectZb;
            if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.N) {
                List<String> xmdmList = examItemList.stream().map(ExamItem::getXmdm).collect(Collectors.toList());
                getSpecialGroupByXmdmReq.setXmdmList(xmdmList);
            }
            Call<Result<List<ExamStuWithSpecialRes>>> call = NetWorkManager.getRequest().getExamStuWithSpecialResByXmdm(getSpecialGroupByXmdmReq);
            call.enqueue(new Callback<Result<List<ExamStuWithSpecialRes>>>() {
                @Override
                public void onResponse(Call<Result<List<ExamStuWithSpecialRes>>> call, Response<Result<List<ExamStuWithSpecialRes>>> response) {
                    Result<List<ExamStuWithSpecialRes>> result = response.body();
                    if (result != null && result.getCode() == 200) {
                        List<ExamStuWithSpecialRes> localExamItemList = result.getData();
                        examStuWithSpecialResList.clear();
                        examStuWithSpecialResList.addAll(localExamItemList);
                        runOnUiThread(() -> {
                            zxStuAdapter.notifyDataSetChanged();
                            groupLayout.setVisibility(View.GONE);
                            selectStu(examStuWithSpecialResList.get(0));
                        });
                    }
                }

                @Override
                public void onFailure(Call<Result<List<ExamStuWithSpecialRes>>> call, Throwable t) {

                }
            });
        }).start();
    }

    private ExamStuWithSpecialRes mExamStu;

    class ZxStuAdapter extends ArrayAdapter<ExamStuWithSpecialRes> {

        public ZxStuAdapter(@NonNull Context context, int resource, @NonNull List<ExamStuWithSpecialRes> objects) {
            super(context, resource, objects);
        }

        //每个子项被滚动到屏幕内的时候会被调用
        @SuppressLint("SetTextI18n")
        @NonNull
        @Override
        public View getView(int position, @Nullable View convertView, @NonNull ViewGroup parent) {
            ExamStuWithSpecialRes examStuWithSpecialRes = getItem(position);//得到当前项的 Fruit 实例
            //为每一个子项加载设定的布局
            View view = LayoutInflater.from(getContext()).inflate(R.layout.item_zxstuscoreitemlist, parent, false);

            if (mExamStu != null && examStuWithSpecialRes.getId() == mExamStu.getId()) {
                view.setBackground(getResources().getDrawable(R.drawable.shape_corner_all_tag));
            } else {
                view.setBackground(getResources().getDrawable(R.drawable.shape_corner_all_white));
            }

            //分别获取 image view 和 textview 的实例
            ImageView photo = view.findViewById(R.id.photo);

            TextView no = view.findViewById(R.id.no);
            TextView name = view.findViewById(R.id.name);
            TextView xh = view.findViewById(R.id.xh);


            no.setText(examStuWithSpecialRes.getKh());
            name.setText(examStuWithSpecialRes.getXm());
            xh.setText("No." + examStuWithSpecialRes.getZxxh());

            new Thread(() -> {
                Bitmap bitmap = bitmapMap.get(examStuWithSpecialRes.getKh());
                if (bitmap == null) {
                    if (examStuWithSpecialRes.getPhoto() != null && !examStuWithSpecialRes.getPhoto().trim().equals("")) {
                        bitmap = BitmapUtils.getBitmapByurl(ConfigManager.getInstance().getApiAddress() + examStuWithSpecialRes.getPhoto());
                        bitmap = BitmapUtils.calculateInSampleSize(bitmap, 100, 100);
                    }
                }
                if (bitmap == null) {
                    if (examStuWithSpecialRes.getXbdm() == null || (examStuWithSpecialRes.getXbdm() != null && examStuWithSpecialRes.getXbdm().equals("1"))) {
                        Resources res = getResources();
                        bitmap = BitmapFactory.decodeResource(res, R.drawable.boy);

                    } else if (examStuWithSpecialRes.getXbdm() != null && examStuWithSpecialRes.getXbdm().equals("2")) {
                        Resources res = getResources();
                        bitmap = BitmapFactory.decodeResource(res, R.drawable.girl);
                    }
                }
                Bitmap finalBitmap = bitmap;
                runOnUiThread(() -> {
                    if (finalBitmap != null) {
                        bitmapMap.put(examStuWithSpecialRes.getKh(), finalBitmap);
                        photo.setImageBitmap(finalBitmap);
                    }
                });
            }).start();
            view.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    selectStu(examStuWithSpecialRes);
                }
            });
            return view;
        }
    }

    private void selectStu(ExamStuWithSpecialRes examStuWithSpecialRes) {
        mExamStu = examStuWithSpecialRes;
        examSpecialArrangeList.clear();
        examSpecialArrangeList.addAll(examStuWithSpecialRes.examSpecialArrangeList);
        zxItemAdapter.notifyDataSetChanged();
        zxStuAdapter.notifyDataSetChanged();
        nameText.setText(examStuWithSpecialRes.getXm());
        kh.setText(examStuWithSpecialRes.getKh());
        zh.setText(examStuWithSpecialRes.getZxzb() + "组");
        xhText.setText(examStuWithSpecialRes.getZxxh() + "号");
    }

    class ZxItemAdapter extends ArrayAdapter<ExamSpecialArrange> {

        public ZxItemAdapter(@NonNull Context context, int resource, @NonNull List<ExamSpecialArrange> objects) {
            super(context, resource, objects);
        }

        //每个子项被滚动到屏幕内的时候会被调用
        @SuppressLint("SetTextI18n")
        @NonNull
        @Override
        public View getView(int position, @Nullable View convertView, @NonNull ViewGroup parent) {
            ExamSpecialArrange examSpecialArrange = getItem(position);//得到当前项的 Fruit 实例
            //为每一个子项加载设定的布局
            View view = LayoutInflater.from(getContext()).inflate(R.layout.item_zxexamitemlist, parent, false);

            TextView xmmcText = view.findViewById(R.id.xmmcText);
            xmmcText.setText(examSpecialArrange.getXmmc());

            ExamItem examItem = null;
            for (int i = 0; i < examItemList.size(); i++) {
                if (examItemList.get(i).getXmdm().equals(examSpecialArrange.getXmdm())) {
                    examItem = examItemList.get(i);
                }
            }

            if (examItem != null && examItem.getXmcs() != null && examItem.getXmcs() > 0) {
                TextView cj1Text = view.findViewById(R.id.cj1);
                if (examSpecialArrange.getCj1() != null) {
                    cj1Text.setText(getCjStr(examSpecialArrange.getCj1(), examItem));
                } else {
                    cj1Text.setText("---");
                }

                cj1Text.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View view) {
                        editSCore(examSpecialArrange, 1);
                    }
                });
            }

            if (examItem != null && examItem.getXmcs() != null && examItem.getXmcs() > 1) {
                TextView cj2Text = view.findViewById(R.id.cj2);
                if (examSpecialArrange.getCj2() != null) {
                    cj2Text.setText(getCjStr(examSpecialArrange.getCj2(), examItem));
                } else {
                    cj2Text.setText("---");
                }
                cj2Text.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View view) {
                        editSCore(examSpecialArrange, 2);
                    }
                });
            }


            if (examItem != null && examItem.getXmcs() != null && examItem.getXmcs() > 2) {
                TextView cj3Text = view.findViewById(R.id.cj3);
                if (examSpecialArrange.getCj3() != null) {
                    cj3Text.setText(getCjStr(examSpecialArrange.getCj3(), examItem));
                } else {
                    cj3Text.setText("---");
                }
                cj3Text.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View view) {
                        editSCore(examSpecialArrange, 3);
                    }
                });
            }


            TextView cjText = view.findViewById(R.id.cj);
            if (examSpecialArrange.getCj() != null) {
                cjText.setText(getCjStr(examSpecialArrange.getCj(), examItem));
            } else {
                cjText.setText("---");
            }
            return view;
        }
    }

    public String getCjStr(String cj, ExamItem examItem) {
        if (cj.equals("-1")) {
            return "犯规";
        } else if (cj.equals("-3")) {
            return "缺考";
        } else if (cj.equals("-4")) {
            return "免考";
        } else if (examItem != null && examItem.getJldw() != null) {
            return cj + examItem.getJldw();
        } else {
            return cj;
        }
    }

    class GroupItemAdapter extends ArrayAdapter<SpecialGroupRes> {

        public GroupItemAdapter(@NonNull Context context, int resource, @NonNull List<SpecialGroupRes> objects) {
            super(context, resource, objects);
        }

        //每个子项被滚动到屏幕内的时候会被调用
        @SuppressLint("SetTextI18n")
        @NonNull
        @Override
        public View getView(int position, @Nullable View convertView, @NonNull ViewGroup parent) {
            SpecialGroupRes specialGroupRes = getItem(position);//得到当前项的 Fruit 实例
            //为每一个子项加载设定的布局
            View view = LayoutInflater.from(getContext()).inflate(R.layout.item_zxgroup, parent, false);
            TextView zbText = view.findViewById(R.id.zbText);
            TextView countText = view.findViewById(R.id.countText);
            CheckBox checkbox = view.findViewById(R.id.checkbox);
            zbText.setText("第" + specialGroupRes.getGroupNum() + "组");
            countText.setText(specialGroupRes.getStuCount() + "人");
            if (specialGroupRes.getGroupNum() == selectZb) {
                checkbox.setChecked(true);
            } else {
                checkbox.setChecked(false);
            }
            view.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    selectZb = specialGroupRes.getGroupNum();
                    groupItemAdapter.notifyDataSetChanged();

                }
            });
            return view;
        }
    }

    public ExamSpecialArrange selectExamSpecialArrange;
    public int selectCount;

    public void editSCore(ExamSpecialArrange examSpecialArrange, int count) {
        this.selectExamSpecialArrange = examSpecialArrange;
        selectCount = count;
        keyBoardLayout.setVisibility(View.VISIBLE);
    }

    Map<String, Bitmap> bitmapMap = new HashMap<>();

    private List<Character> inputStr = new ArrayList<>();

    public void onKey(View view) {
        int id = view.getId();
        System.out.println(id);
        if (id == R.id.key1) {
            inputStr.add('1');
        }
        if (id == R.id.key2) {
            inputStr.add('2');
        }
        if (id == R.id.key3) {
            inputStr.add('3');
        }
        if (id == R.id.key4) {
            inputStr.add('4');
        }
        if (id == R.id.key5) {
            inputStr.add('5');
        }
        if (id == R.id.key6) {
            inputStr.add('6');
        }
        if (id == R.id.key7) {
            inputStr.add('7');
        }
        if (id == R.id.key8) {
            inputStr.add('8');
        }
        if (id == R.id.key9) {
            inputStr.add('9');
        }
        if (id == R.id.keydy) {
            inputStr.add('.');
        }
        if (id == R.id.keysy) {
            inputStr.add(':');
        }
        if (id == R.id.key0) {
            inputStr.add('0');
        }
        if (id == R.id.keydiscount) {
            inputStr.add('-');
        }

        if (id == R.id.keydelete) {
            if (inputStr.size() > 0) {
                inputStr.remove(inputStr.size() - 1);
            }
        }

        if (id == R.id.keyconfirm) {
            updateScore();
        }
        if (id == R.id.keycancel && !isUpdate) {
//            this.setVisibility(GONE);
            inputStr.clear();
            inputText.setText("");
            keyBoardLayout.setVisibility(View.GONE);
        }


        String result = null;
        if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.N) {
            result = inputStr.stream()
                    .map(String::valueOf)
                    .collect(Collectors.joining());
        }
        inputText.setText(result);
    }

    boolean isUpdate = false;

    private void updateScore() {
        if (isUpdate) {
            return;
        }
        isUpdate = true;
        String result = null;
        if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.N) {
            result = inputStr.stream()
                    .map(String::valueOf)
                    .collect(Collectors.joining());
        }
        QMUITipDialog tipDialog = new QMUITipDialog.Builder(this)
                .setIconType(QMUITipDialog.Builder.ICON_TYPE_LOADING)
                .setTipWord("提交中")
                .create();
        tipDialog.show();

        ExamSpecialScoreReq examSpecialScoreReq = new ExamSpecialScoreReq();
        examSpecialScoreReq.setId(selectExamSpecialArrange.getId());
        examSpecialScoreReq.setCount((long) selectCount);
        if (result.equals("犯规")) {
            result = "-1";
        }
        if (result.equals("缺考")) {
            result = "-3";
        }
        if (result.equals("免考")) {
            result = "-4";
        }
        examSpecialScoreReq.setRawScore(result);
        Call<Result<ExamSpecialArrange>> call = NetWorkManager.getRequest().setSpecialScore(examSpecialScoreReq);
        String finalResult = result;
        call.enqueue(new Callback<Result<ExamSpecialArrange>>() {
            @Override
            public void onResponse(Call<Result<ExamSpecialArrange>> call, Response<Result<ExamSpecialArrange>> response) {

                if (response.code() == 200 && response.body().getCode() == 200) {
                    ExamSpecialArrange examSpecialArrange = response.body().getData();
                    inputStr.clear();
                    inputText.setText("");
                    keyBoardLayout.setVisibility(View.GONE);
                    Toast.makeText(getBaseContext(), "提交成功", Toast.LENGTH_SHORT).show();
                    if (selectCount == 1) {
                        selectExamSpecialArrange.setCj1(examSpecialArrange.getCj1());
                    }
                    if (selectCount == 2) {
                        selectExamSpecialArrange.setCj2(examSpecialArrange.getCj2());
                    }
                    if (selectCount == 3) {
                        selectExamSpecialArrange.setCj3(examSpecialArrange.getCj3());
                    }
                    selectExamSpecialArrange.setCj(examSpecialArrange.getCj());
                    zxItemAdapter.notifyDataSetChanged();
                } else {
                    Toast.makeText(getBaseContext(), response.body().getMsg(), Toast.LENGTH_SHORT).show();
                }
                isUpdate = false;
                tipDialog.dismiss();
            }

            @Override
            public void onFailure(Call<Result<ExamSpecialArrange>> call, Throwable t) {
                isUpdate = false;
                tipDialog.dismiss();
            }
        });
    }

    private boolean delete(View view) {
        inputStr.clear();
        String result = null;
        if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.N) {
            result = inputStr.stream()
                    .map(String::valueOf)
                    .collect(Collectors.joining());
        }
        inputText.setText(result);
        return true;
    }

    private void selectZb(View view) {
        groupLayout.setVisibility(View.VISIBLE);
//        final String[] items2 = new String[]{"男子铅球", "男子铁饼", "男子标枪", "女子铅球", "女子铁饼", "女子标枪", "男子标枪（竹枪600g以上）", "女子标枪（竹枪400g以上）"};
//        final QMUIDialog.CheckableDialogBuilder builder2 = new QMUIDialog.CheckableDialogBuilder(ZxUpdateScoreActivity.this);
//        builder2.setTitle("请选择")
//                .setCheckedIndex(0)
//                .addItems(items2, new DialogInterface.OnClickListener() {
//                    @Override
//                    public void onClick(DialogInterface dialog, int which) {
//                        builder2.setCheckedIndex(which);
//                    }
//                })
//                .addAction("确定", new QMUIDialogAction.ActionListener() {
//                    @Override
//                    public void onClick(QMUIDialog dialog, int index) {
//                        Toast.makeText(ZxUpdateScoreActivity.this, "你选择了 " + items2[builder2.getCheckedIndex()], Toast.LENGTH_SHORT).show();
//                        dialog.dismiss();
//                    }
//                })
//                .show();
    }
}
